import { AddressProps as AddressType } from "@/pages/address/address";

import {
    SELECT_ADDRESS,
    UPDATE_ADDRESS_SHOW_MODAL,
} from '../actions';

export interface AddressState {
    addressList: AddressType[];
    addressId: number | string;
    selectedAddress: AddressType;
    showAddressModel: boolean; // // 新增：弹框显示状态
}

const initState: AddressState = {
    addressList: [],
    addressId: 0,
    selectedAddress: {},
    showAddressModel: false,
};

export default function addressReducer(state = initState, action: any): AddressState {
    switch (action.type) {
        case SELECT_ADDRESS:
            return {
                ...state,
                selectedAddress: action.payload,
            };
        case UPDATE_ADDRESS_SHOW_MODAL:
            return {
                ...state,
                showAddressModel: action.payload,
            };
        default:
            return state;
    }
}

